<template>
    <div>
        <p v-for="(item,index) in itemTitle" v-bind:key="index"  v-on:click="activeItem(index)">
            <span :class="{active:currentIndex===index}">{{item}}</span>

        </p>
    </div>
</template>

<script>
export default {
    name: "CategoryItem",
    data(){
        return{
            currentIndex:0
        }
    },
    methods:{
        activeItem(index){
            this.currentIndex=index
            this.$emit('categoryItemIndex',index)
        }
    },
    props:{
        itemTitle:{
            type:Array,
            default:function (){
                return []
            }
        }
    }
}
</script>

<style scoped>
.active{
    color: red;
    border-bottom: 3px solid red;
}
p{
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    width: 100%;
    display: inline-block;
    text-align: center;
}
</style>
